from django.core.mail import EmailMultiAlternatives, send_mass_mail
from conf.config import DEFAULT_FROM_EMAIL
import sys, os
BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(BASE_PATH)

HTML_PATH = os.path.join(BASE_PATH, 'report')


class MailBot:

	def __init__(self):
		pass

	def mass_test(self, subject, message, from_email, mails):
		"""
		:param str subject: 邮件主题
		:param str message: 邮箱内容
		:parm list mails: 收件人邮箱
		"""
		send_mass_mail(((subject, message, from_email, mails),), fail_silently=False)

	def s_mail(self, subject, from_mail, to, text_content):
		# subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
		text_content = 'This is an important message. <br>'
		html_content = '<a href="http://www.baidu.com"><img src="https://user-images.githubusercontent.com/19553554/55601215-656d1480-5792-11e9-87ac-19b912619d7f.png" data-origin="https://user-images.githubusercontent.com/19553554/55601215-656d1480-5792-11e9-87ac-19b912619d7f.png" alt="" class="medium-zoom-image"></a>'
		html_content = '<html><head><title>502 Bad Gateway</title></head><body bgcolor="white"><center><h1>502 Bad Gateway</h1></center><hr><center>nginx</center></body></html>'
		print(text_content)
		msg = EmailMultiAlternatives(subject, text_content, from_mail, to)
		msg.attach_alternative(html_content, "text/html")
		msg.content_subtype = 'html'
		msg.send()

